<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/commons/global.jsp"%>

<div id="tag-setting-div" class="easyui-window" title="设置类别"
	style="width: 1000px; height: 500px"
	data-options="iconCls:'icon-cog',modal:true,openAnimation:'fade',closeAnimation:'slide',cache:false,collapsible:false,minimizable:false,maximizable:false">
	<div class="content-wrapper">
		<div class="title-wrapper" style="float: left; width: 640px;">
			<%-- 			<div>资源类型:${itemType.code }</div> --%>
			<div style="float: left; width: 100px;">资源类型:${itemType.msg }</div>
			<div style="float: left; width: 100px;">资源ID:${entity.id }</div>
			<div style="float: left;">标题:${entity.title }</div>
			<div style="clear: both;"></div>
			<div>
				<img alt="" src="${entity.coverUrl }"
					style="width: 640px; height: 360px;" />
			</div>
		</div>

		<div class="tag-wrapper" style="float: right; width: 300px;">
			<div class="title">
				<input id="setTag_tagContentTree_tagNameQue" style="width: 200px;" />
			</div>
			<div class="content"></div>
		</div>
		<div style="clear: both;"></div>
	</div>
</div>


<script type="text/javascript">
	function setTag_tagContentTreeReload() {
		try {
			setTag_tagContentTree.tree("options").queryParams = {
				like_name : setTag_tagContentTree_tagNameQue
						.textbox('getValue')
			};
			setTag_tagContentTree.tree('reload');
		} catch (e) {
		}
	}
</script>

<script type="text/javascript">
	var setTag_tagContentTree_tagNameQue = undefined;
	var setTag_tagContentTree = undefined;
	$(function() {
		setTag_tagContentTree_tagNameQue = $(
				'#setTag_tagContentTree_tagNameQue').textbox({
			buttonText : '标签名搜索',
			buttonIcon : 'icon-search',
			buttonAlign : 'right'
		});

		setTag_tagContentTree_tagNameQue.textbox('button').click(function() {
			setTag_tagContentTreeReload();
		});

		var tag_setting_div = $('#tag-setting-div').window({
			onBeforeClose : function() {

			},
			onClose : function() {
				tag_setting_div.panel('destroy');
			}
		});

		var _val = {
			attribute : {
				ckey : 'list-'
			},
			text : '标签'
		};
		$('#tag-setting-div .tag-wrapper .content')
				.append(
						'<div id="'+_val.attribute.ckey+'tagContent" style="padding: 5px"><ul id="'+_val.attribute.ckey+'tagContentTree"></ul></div>');

		$('#' + _val.attribute.ckey + 'tagContent').panel(
				{
					tools : [ {
						iconCls : 'icon-save',
						handler : function() {
							var nodes = $(
									'#' + _val.attribute.ckey
											+ 'tagContentTree').tree(
									'getChecked');
							if (!nodes || nodes.length < 1) {
								$.messager.alert('提示', '请选择' + _val.text,
										'warning');
								return;
							}
							var textArr = new Array();
							var typeArr = new Array();

							for ( var i = 0; i < nodes.length; i++) {
								textArr.push(nodes[i].text);
								typeArr.push(nodes[i].id);
							}
							$.messager.confirm('确认', _val.text + ':'
									+ textArr.join(',') + '<br />确定设置?',
									function(r) {
										if (r) {
											var _data = {
												ckey : _val.attribute.ckey,
												tagIds : typeArr,
												itemType : '${itemType.code}',
												itemId : '${entity.id}'
											};
											$
													.ajax({
														async : false,
														data : _data,
														type : "post",
														url : baseUrl
																+ '/tag/set',
														success : function(
																responseData) {
															$.messager.alert(
																	'提示',
																	'添加成功',
																	'info');
														}
													});
										}
									});
						}
					} ],
					width : 300,
					title : '设置' + _val.text
				});

		setTag_tagContentTree = $('#' + _val.attribute.ckey + 'tagContentTree')
				.tree(
						{
							url : '${baseUrl }/tag/list?itemType=${itemType.code }&itemId=${entity.id}',
							method : 'post',
							animate : true,
							checkbox : true,
							onlyLeafCheck : true,
							lines : true
						});

	});
</script>